package com.crowd.dao.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.crowd.dao.UserDao;
import com.crowd.entity.User;

import utill.DButill;

public class UserDaoimpl extends DButill implements UserDao{

	@Override
	public List<User> dan(User user) {
		String sql="select * from user where name=? and pswd=?";
		List<User> users=new ArrayList<User>();
		try {
			open_db();
			pst=conn.prepareStatement(sql);
			pst.setString(1, user.getName());
			pst.setInt(2, user.getPswd());
			rs=pst.executeQuery();
			while (rs.next()) {
				User user2=new User();
				user2.setName(rs.getString("name"));
				user2.setPswd(rs.getInt("pswd"));
				users.add(user2);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return users;
	}

	@Override
	public boolean add(User user) {
		String sql="INSERT user VALUES(?,?)";
		int sult=0;
		try {
			open_db();
			pst=conn.prepareStatement(sql);
			pst.setString(1, user.getName());
			pst.setInt(2, user.getPswd());
			sult=pst.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return sult>0;
	}
       
}
